package com.rms.server.Controller;

import com.rms.server.DTO.DishWithIngredientsDTO;
import com.rms.server.Service.DishIngredientAssociationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dish-ingredient-association")
@Tag(name = "菜品原料关联管理", description = "菜品与原料关联关系的管理接口")
public class DishIngredientAssociationController {

    @Autowired
    private DishIngredientAssociationService dishIngredientAssociationService;
    // 添加菜品原料关联
    @PostMapping("/add")
    @Operation(summary = "新增菜品原料关联", description = "创建新的菜品与原料的关联关系")
    public String addDishIngredientAssociation(
            @Parameter(description = "菜品ID", required = true) @RequestParam Long dishId,
            @Parameter(description = "原料ID", required = true) @RequestParam Long ingredientId,
            @Parameter(description = "使用的原料数量", required = true) @RequestParam double quantityUsed) {
        return dishIngredientAssociationService.addDishIngredientAssociation(dishId, ingredientId, quantityUsed);
    }
    // 获取所有菜品及其原料信息
    @GetMapping("/all")
    @Operation(summary = "获取所有菜品及其原料信息", description = "获取所有菜品名称，及对应的原材料及所需的分量")
    public List<DishWithIngredientsDTO> getAllDishesWithIngredients() {
        return dishIngredientAssociationService.getAllDishesWithIngredients();
    }
    // 根据菜品ID获取菜品及其原料信息
    @GetMapping("/{dishId}")
    @Operation(summary = "根据菜品ID获取菜品及其原料信息", description = "根据菜品ID获取菜品名称，及对应的原材料及所需的分量")
    public DishWithIngredientsDTO getDishWithIngredientsById(
            @Parameter(description = "菜品ID", required = true) @PathVariable Long dishId) {
        return dishIngredientAssociationService.getDishWithIngredientsById(dishId);
    }

}